/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.aionemu.gameserver.model.gameobjects.stats;

import com.aionemu.gameserver.model.gameobjects.stats.modifiers.StatModifier;
import com.aionemu.gameserver.skillengine.model.IStatEffect;

/**
 * @author Mr. Poke
 *
 */
public class OwnedStatModifier implements Comparable<OwnedStatModifier>
{
	/**
	 * @param owner
	 * @param statModifier
	 */
	public OwnedStatModifier(IStatEffect owner, StatModifier statModifier)
	{
		this.owner = owner;
		this.statModifier = statModifier;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((owner == null) ? 0 : owner.hashCode());
		result = prime * result + ((statModifier == null) ? 0 : statModifier.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OwnedStatModifier other = (OwnedStatModifier) obj;
		if (owner == null)
		{
			if (other.owner != null)
				return false;
		}
		else if (!owner.equals(other.owner))
			return false;
		if (statModifier == null)
		{
			if (other.statModifier != null)
				return false;
		}
		else if (!statModifier.equals(other.statModifier))
			return false;
		return true;
	}

	private IStatEffect owner;
	private StatModifier statModifier;

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(OwnedStatModifier o)
	{
		int result = statModifier.compareTo(o.statModifier);
		if (result == 0 && owner != null)
			return owner.hashCode()-o.owner.hashCode();
		return result;
	}

	/**
	 * @return Returns the owner.
	 */
	public IStatEffect getOwner()
	{
		return owner;
	}
	/**
	 * @return Returns the statModifier.
	 */
	public StatModifier getStatModifier()
	{
		return statModifier;
	}
}
